package cn.ren.cloud.service.impl;

import cn.ren.cloud.domain.CourseUserLearn;
import cn.ren.cloud.mapper.CourseUserLearnMapper;
import cn.ren.cloud.service.ICourseUserLearnService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Ren
 * @since 2022-12-31
 */
@Service
public class CourseUserLearnServiceImpl extends ServiceImpl<CourseUserLearnMapper, CourseUserLearn> implements ICourseUserLearnService {

    /**
     * 通过ID效验是否购买课程
     *
     * @param courseId
     * @param loginId
     * @return
     */
    @Override
    public CourseUserLearn getByCourseId(Long courseId, Long loginId) {
        Wrapper<CourseUserLearn> wrapper = new EntityWrapper<>();
        wrapper.eq("course_id", courseId);
        wrapper.eq("login_id", loginId);
        return selectOne(wrapper);
    }

    /**
     * 获取loinId
     *
     * @param loginId
     * @return
     */
    @Override
    public List<CourseUserLearn> selectByLoginId(Long loginId) {
        Wrapper<CourseUserLearn> wrapper = new EntityWrapper<>();
        wrapper.eq("login_id", loginId);
        return selectList(wrapper);
    }
}
